﻿
//	------------------------------------------------------------------------------
//                                       _                          
//              _ __ ___   ___ _ __ ___ | |__  _ __ __ _ _ __   ___ 
//             | '_ ` _ \ / _ \ '_ ` _ \| '_ \| '__/ _` | '_ \ / _ \
//             | | | | | |  __/ | | | | | |_) | | | (_| | | | |  __/
//             |_| |_| |_|\___|_| |_| |_|_.__/|_|  \__,_|_| |_|\___|
//                                                     
//	------------------------------------------------------------------------------

#region - License -
//
//	------------------------------------------------------------------------------                                                   
//	         Copyright (c) 2010 Peter Vyvey (peter.vyvey@chiliware.be)
//	------------------------------------------------------------------------------
//
//
//	This file is part of CHILIWARE MEMBRANE.
//
//	CHILIWARE MEMBRANE is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	CHILIWARE MEMBRANE is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU Lesser General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public License
//	along with CHILIWARE MEMBRANE.  If not, see <http://www.gnu.org/licenses/>.
//
//
#endregion

#region - Changes -

//	peter.vyvey@chiliware.be     2010-08-09      Created.

#endregion

#region - Using -

using System;
using System.Collections.Generic;

#endregion

namespace Chiliware.Membrane.Extension
{
	#region - EventHandlerExtension -

	/// <summary>
	/// Extension methods to handle extra functionality on event handlers
	/// </summary>
	public static class EventHandlerExtension
	{
		#region - Public static methods -

		/// <summary>
		/// Raises the event.
		/// </summary>
		/// <param name="handler">The event handler.</param>
		/// <param name="sender">The sender of the event.</param>
		public static void Raise(this EventHandler handler, object sender)
		{
			EventHandler local = handler;
			if (local != null)
			{
				local(sender, EventArgs.Empty);
			}
		}

		/// <summary>
		/// Raises the event with the specified type of event arguments.
		/// </summary>
		/// <typeparam name="T">The type of the event arguments.</typeparam>
		/// <param name="handler">The event handler.</param>
		/// <param name="sender">The sender of the event.</param>
		/// <param name="args">The event arguments.</param>
		public static void Raise<T>(this EventHandler<T> handler, object sender, T args)
			where T : EventArgs
		{
			EventHandler<T> local = handler;

			if (local != null)
			{
				local(sender, args);
			}
		}

		#endregion
	}

	#endregion
}
